Skip to content

Comments

fix: Missing Delete key handlers#2126

Open
matthewlipski wants to merge 6 commits intomainfrom
delete-handler-imprevements
Open

fix: Missing Delete key handlers#2126
matthewlipski wants to merge 6 commits intomainfrom
delete-handler-imprevements

Conversation

@matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Oct 23, 2025

Summary

This PR adds full Delete key handling, building on the existing logic. The additional cases are mainly for nested blocks and multi-column blocks.

R.e. multi-column, Backspace key handling has also been slightly changed to be more consistent. Specifically, whenever a block moves into a column after pressing Backspace or Delete, it now always gets added as a new block. Previously, it would sometimes be merged with the current block.

Rationale

While Delete isn't used as much as Backspace, proper handling for it is still needed.

Changes

  • Added cases for Delete key handling.
  • Added a case for Backspace key handling when right after columnList.
  • Added getNextBlockInfo helper.
  • Updated getParentBlockInfo helper.

Impact

N/A

Testing

Added e2e tests for Delete key handling:

  • Basic functionality (merging adjacent blocks, deleting selection, etc.)
  • Nested blocks (merging child with parent, merging next block with child, etc.)
  • Multi-column (moving the first block from the next column into the current one, moving the first block in a column list out of it, etc.)

Screenshots/Video

N/A

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

@vercel
Copy link

vercel bot commented Oct 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Feb 23, 2026 9:03pm
blocknote-website Ready Ready Preview Feb 23, 2026 9:03pm

Request Review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 23, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@2126

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@2126

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@2126

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@2126

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@2126

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@2126

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@2126

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@2126

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@2126

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@2126

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@2126

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@2126

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@2126

commit: 98c5f36

Copy link
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will hold on this until we get that PR through

Comment on lines +22 to +26
// TODO: This works for blockContainer nodes as we need to traverse 2
// nesting levels due to the blockGroup in between. However, that's not the
// case for columns.
$pos.index($pos.depth - 2),
$pos.depth - 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, let's do this

Comment on lines +96 to +102
if (
!prevBlockInfo ||
!prevBlockInfo.isBlockContainer ||
prevBlockInfo.blockContent.node.type.spec.content !== "inline*"
) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a todo on why we early return here

Comment on lines 200 to +201
tr.setSelection(
TextSelection.near(tr.doc.resolve($columnPos.pos - 1)),
TextSelection.near(tr.doc.resolve($columnPos.pos)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text selection is after now? Intentional?

Copy link
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you test the delete key on macOS? I'm unsure how to do it

Comment on lines +708 to +725
if (nextBlockInfo.bnBlock.node.childCount === 2) {
const childBlocks =
nextBlockInfo.bnBlock.node.lastChild!.content;
return chain()
.deleteRange({
from: nextBlockInfo.bnBlock.beforePos,
to: nextBlockInfo.bnBlock.afterPos,
})
.insertContentAt(blockInfo.bnBlock.afterPos, childBlocks)
.run();
}

return chain()
.deleteRange({
from: nextBlockInfo.bnBlock.beforePos,
to: nextBlockInfo.bnBlock.afterPos,
})
.run();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two can be merged right. insetContentAt accepts null no-ops right

@matthewlipski
Copy link
Collaborator Author

How do you test the delete key on macOS? I'm unsure how to do it

I think it's Fn+Backspace but not 100% sure since I use a keyboard with Windows modifiers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants